﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Yozeev.Migrations
{
    public partial class Add_CommonCustomer : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "CommonCustomers",
                schema: "Common",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    BranchId = table.Column<Guid>(nullable: true),
                    MainCustomerId = table.Column<Guid>(maxLength: 65, nullable: false),
                    ViceCustomerId = table.Column<Guid>(maxLength: 65, nullable: false),
                    CustomerName = table.Column<string>(maxLength: 65, nullable: false),
                    Mobile = table.Column<string>(maxLength: 65, nullable: false),
                    Sex = table.Column<int>(maxLength: 65, nullable: false),
                    CertificatesNum = table.Column<string>(maxLength: 65, nullable: false),
                    VerifiableType = table.Column<int>(maxLength: 65, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CommonCustomers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CommonCustomers_Branchs_BranchId",
                        column: x => x.BranchId,
                        principalSchema: "Basics",
                        principalTable: "Branchs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_CommonCustomers_Users_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalSchema: "ABP",
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_CommonCustomers_Customers_ViceCustomerId",
                        column: x => x.ViceCustomerId,
                        principalSchema: "Common",
                        principalTable: "Customers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CommonCustomers_BranchId",
                schema: "Common",
                table: "CommonCustomers",
                column: "BranchId");

            migrationBuilder.CreateIndex(
                name: "IX_CommonCustomers_CreatorUserId",
                schema: "Common",
                table: "CommonCustomers",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_CommonCustomers_ViceCustomerId",
                schema: "Common",
                table: "CommonCustomers",
                column: "ViceCustomerId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "CommonCustomers",
                schema: "Common");
        }
    }
}
